package com.fr.web.face;

import com.fr.base.CodeUtils;
import com.fr.base.FRContext;
import com.fr.base.file.ConfigManager;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.privilege.authentication.Authentication;
import com.fr.privilege.filter.core.TemplateAccessDealWith;
import com.fr.report.parameter.Parameter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

public class ViewReportletDef extends AbstractNodeDef
{
  private List reportletInfoList = new ArrayList();

  public int getReportletInfoCount()
  {
    return this.reportletInfoList.size();
  }

  public ReportletInfo getReportletInfo(int paramInt)
  {
    return ((ReportletInfo)this.reportletInfoList.get(paramInt));
  }

  public void addReportletInfo(ReportletInfo paramReportletInfo)
  {
    this.reportletInfoList.add(paramReportletInfo);
  }

  public void setReportletInfo(int paramInt, ReportletInfo paramReportletInfo)
  {
    this.reportletInfoList.set(paramInt, paramReportletInfo);
  }

  public void clearReportletInfos()
  {
    this.reportletInfoList.clear();
  }

  public Access createURI(HttpServletRequest paramHttpServletRequest, Authentication paramAuthentication)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = getReportletInfoCount();
    if (i > 0)
    {
      ReportletInfo localReportletInfo;
      int k;
      Parameter localParameter;
      localStringBuffer.append(FRContext.getConfigManager().getServletMapping()).append("?");
      if (i == 1)
      {
        localReportletInfo = getReportletInfo(0);
        if ((paramAuthentication != null) && (!(TemplateAccessDealWith.hasLegalAccess(localReportletInfo.getReporletPath(), 0, paramAuthentication))))
          return new Access("", false);
        localStringBuffer.append("reportlet=").append(CodeUtils.encodeURIComponent(localReportletInfo.getReporletPath()));
        j = localReportletInfo.getParameterCount();
        if (j <= 0)
          break label322;
        k = 0;
        while (true)
        {
          if (k >= j)
            break label322;
          localStringBuffer.append("&");
          localParameter = localReportletInfo.getParameter(k);
          localStringBuffer.append(CodeUtils.encodeURIComponent(localParameter.getName())).append("=").append(CodeUtils.encodeURIComponent(localParameter.valueToString()));
          ++k;
        }
      }
      localStringBuffer.append("reportlets=");
      localStringBuffer.append("(");
      for (int j = 0; j < i; ++j)
      {
        int l;
        localReportletInfo = getReportletInfo(j);
        if (j != 0)
          localStringBuffer.append(",");
        localStringBuffer.append("{reportlet:").append(CodeUtils.encodeURIComponent(localReportletInfo.getReporletPath()));
        k = localReportletInfo.getParameterCount();
        if (k > 0)
          for (l = 0; l < k; ++l)
          {
            localStringBuffer.append(",");
            localParameter = localReportletInfo.getParameter(l);
            localStringBuffer.append(CodeUtils.encodeURIComponent(localParameter.getName())).append(":").append(CodeUtils.encodeURIComponent(localParameter.valueToString()));
          }
        localStringBuffer.append("}");
      }
      localStringBuffer.append(")");
    }
    label322: return new Access(CodeUtils.cjkEncode(localStringBuffer.toString()), true);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && ("ReportletInfo".equals(paramXMLableReader.getTagName())))
    {
      ReportletInfo localReportletInfo = new ReportletInfo();
      paramXMLableReader.readXMLObject(localReportletInfo);
      addReportletInfo(localReportletInfo);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    int i = getReportletInfoCount();
    for (int j = 0; j < i; ++j)
    {
      ReportletInfo localReportletInfo = getReportletInfo(j);
      localReportletInfo.writeXML(paramXMLPrintWriter);
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}